﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapWTGEW(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWTGEW(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTGEW(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWTGEW(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWTGEW(dwLocal);
            }
            UpdateWTGEW(dwLocal);
        }
        public void InsertWTGEW(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO WTGEW(WTGMANDANT, WTGKUNDNR, WTGWERK, WTGABT, WTGART, WTGVAR, WTGAENZL, WTGAENB, WTGAEND, WTGNEUB, WTGNEUD, WTGWBBRT, WTGWBF, WTGFDISM, WTGFDLGS, WTGFDLFS, WTGSFLG, WTGKCOL, WTGSMTRS, WTGREAPPI, WTGRNAME, WTGCHORE, WTGRDENS, WTGRDENSTM, WTGRDENSTP, WTGKARTEN, WTGPLATINEN, WTGNOPPEN, WTGANZRAPP, WTGRWRAPH, WTGRWRAPB, WTGRWRAPHFD, WTGRWRAPBFD, WTGPANELS, WTGSHEDS, WTGNFLRH, WTGNFLRA, WTGNFTOLM, WTGNFTOLP, WTGMFLRH, WTGMFLRA, WTGMFTOLM, WTGMFTOLP, WTGHFLRH, WTGHFLRA, WTGHFTOLM, WTGHFTOLP, WTGFILLER)"
                + "VALUES (:WTGMANDANT, '00000000', '   ', '   ', :WTGART, :WTGVAR, 1, '        ', 0, '        ', 0, 0, 0, 0, 0, 0, 'A              ', '0', 0, '               ', '               ', '0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '000', '0', 0, '   ', 0, 0, 0, '   ', 0, 0, 0, '   ', 0, 0, '                                                  ')";
            or1.Parameters.Add("WTGMANDANT", OracleType.NVarChar).Value = dwData["WTGMANDANT"].ToString();
            or1.Parameters.Add("WTGART", OracleType.NVarChar).Value = dwData["WTGART"].ToString();
            or1.Parameters.Add("WTGVAR", OracleType.NVarChar).Value = dwData["WTGVAR"].ToString();
            Connect2Proxy(or1);
        }
        public void DeleteWTGEW(string client, string art, string var)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE WTGEW WHERE   "
            + "  WTGMANDANT=:WTGMANDANT AND WTGART=:WTGART AND WTGVAR=:WTGVAR";
            or1.Parameters.Add("WTGMANDANT", OracleType.NVarChar).Value = client;
            or1.Parameters.Add("WTGART", OracleType.NVarChar).Value = art;
            or1.Parameters.Add("WTGVAR", OracleType.NVarChar).Value = var;
            Connect2Proxy(or1);
        }
        public DataSet QueryWTGEW(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            //select * from WTGEW where WTGART='PV912102            ' AND WTGVAR='12'

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM WTGEW WHERE   "
                    + "  WTGMANDANT=:WTGMANDANT AND WTGART=:WTGART AND WTGVAR=:WTGVAR";
                    or1.Parameters.Add("WTGMANDANT", OracleType.NVarChar).Value = dwData["WTGMANDANT"].ToString();
                    or1.Parameters.Add("WTGART", OracleType.NVarChar).Value = dwData["WTGART"].ToString();
                    or1.Parameters.Add("WTGVAR", OracleType.NVarChar).Value = dwData["WTGVAR"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT DISTINCT WD.WDAUFKRS,WDAUFLFD,WDAUFPOS,WDSA,WDUPOS,W.* FROM WDECK  WD "
                   + " JOIN WTGEW W ON WDART=W.WTGART AND WDVAR=W.WTGVAR "
                   + " WHERE WDMANDANT=:WDMANDANT AND WDSA='K' AND WDTYP='B' AND WDWAKZ='F' AND WDAUFKRS=:WDAUFKRS  AND WDAUFLFD=:WDAUFLFD";
                    or1.Parameters.Add("WDMANDANT", OracleType.NVarChar).Value = dwData["WDMANDANT"].ToString();
                    or1.Parameters.Add("WDAUFKRS", OracleType.NVarChar).Value = dwData["WDAUFKRS"].ToString();
                    or1.Parameters.Add("WDAUFLFD", OracleType.NVarChar).Value = dwData["WDAUFLFD"].ToString();
                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "WTGEW";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public void UpdateWTGEW(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE WTGEW SET "
                + "WTGMANDANT=:WTGMANDANT,"
                + "WTGKUNDNR=:WTGKUNDNR,"
                + "WTGWERK=:WTGWERK,"
                + "WTGABT=:WTGABT,"
                + "WTGART=:WTGART,"
                + "WTGVAR=:WTGVAR,"
                + "WTGAENZL=:WTGAENZL,"
                + "WTGAENB=:WTGAENB,"
                + "WTGAEND=:WTGAEND,"
                + "WTGNEUB=:WTGNEUB,"
                + "WTGNEUD=:WTGNEUD,"
                + "WTGWBBRT=:WTGWBBRT,"
                + "WTGWBF=:WTGWBF,"
                + "WTGFDISM=:WTGFDISM,"
                + "WTGFDLGS=:WTGFDLGS,"
                + "WTGFDLFS=:WTGFDLFS,"
                + "WTGSFLG=:WTGSFLG,"
                + "WTGKCOL=:WTGKCOL,"
                + "WTGSMTRS=:WTGSMTRS,"
                + "WTGREAPPI=:WTGREAPPI,"
                + "WTGRNAME=:WTGRNAME,"
                + "WTGCHORE=:WTGCHORE,"
                + "WTGRDENS=:WTGRDENS,"
                + "WTGRDENSTM=:WTGRDENSTM,"
                + "WTGRDENSTP=:WTGRDENSTP,"
                + "WTGKARTEN=:WTGKARTEN,"
                + "WTGPLATINEN=:WTGPLATINEN,"
                + "WTGNOPPEN=:WTGNOPPEN,"
                + "WTGANZRAPP=:WTGANZRAPP,"
                + "WTGRWRAPH=:WTGRWRAPH,"
                + "WTGRWRAPB=:WTGRWRAPB,"
                + "WTGRWRAPHFD=:WTGRWRAPHFD,"
                + "WTGRWRAPBFD=:WTGRWRAPBFD,"
                + "WTGPANELS=:WTGPANELS,"
                + "WTGSHEDS=:WTGSHEDS,"
                + "WTGNFLRH=:WTGNFLRH,"
                + "WTGNFLRA=:WTGNFLRA,"
                + "WTGNFTOLM=:WTGNFTOLM,"
                + "WTGNFTOLP=:WTGNFTOLP,"
                + "WTGMFLRH=:WTGMFLRH,"
                + "WTGMFLRA=:WTGMFLRA,"
                + "WTGMFTOLM=:WTGMFTOLM,"
                + "WTGMFTOLP=:WTGMFTOLP,"
                + "WTGHFLRH=:WTGHFLRH,"
                + "WTGHFLRA=:WTGHFLRA,"
                + "WTGHFTOLM=:WTGHFTOLM,"
                + "WTGHFTOLP=:WTGHFTOLP,"
                + "WTGFILLER=:WTGFILLER "
                + " WHERE  "
                + "  WTGMANDANT=:WTGMANDANT AND WTGART=:WTGART  AND WTGVAR=:WTGVAR ";
            or1.Parameters.Add("WTGMANDANT", OracleType.NVarChar).Value = dwData["WTGMANDANT"].ToString();
            or1.Parameters.Add("WTGKUNDNR", OracleType.NVarChar).Value = dwData["WTGKUNDNR"].ToString();
            or1.Parameters.Add("WTGWERK", OracleType.NVarChar).Value = dwData["WTGWERK"].ToString();
            or1.Parameters.Add("WTGABT", OracleType.NVarChar).Value = dwData["WTGABT"].ToString();
            or1.Parameters.Add("WTGART", OracleType.NVarChar).Value = dwData["WTGART"].ToString();
            or1.Parameters.Add("WTGVAR", OracleType.NVarChar).Value = dwData["WTGVAR"].ToString();
            or1.Parameters.Add("WTGAENZL", OracleType.NVarChar).Value = dwData["WTGAENZL"].ToString();
            or1.Parameters.Add("WTGAENB", OracleType.NVarChar).Value = dwData["WTGAENB"].ToString();
            or1.Parameters.Add("WTGAEND", OracleType.NVarChar).Value = dwData["WTGAEND"].ToString();
            or1.Parameters.Add("WTGNEUB", OracleType.NVarChar).Value = dwData["WTGNEUB"].ToString();
            or1.Parameters.Add("WTGNEUD", OracleType.NVarChar).Value = dwData["WTGNEUD"].ToString();
            or1.Parameters.Add("WTGWBBRT", OracleType.NVarChar).Value = dwData["WTGWBBRT"].ToString();
            or1.Parameters.Add("WTGWBF", OracleType.NVarChar).Value = dwData["WTGWBF"].ToString();
            or1.Parameters.Add("WTGFDISM", OracleType.NVarChar).Value = dwData["WTGFDISM"].ToString();
            or1.Parameters.Add("WTGFDLGS", OracleType.NVarChar).Value = dwData["WTGFDLGS"].ToString();
            or1.Parameters.Add("WTGFDLFS", OracleType.NVarChar).Value = dwData["WTGFDLFS"].ToString();
            or1.Parameters.Add("WTGSFLG", OracleType.NVarChar).Value = dwData["WTGSFLG"].ToString();
            or1.Parameters.Add("WTGKCOL", OracleType.NVarChar).Value = dwData["WTGKCOL"].ToString();
            or1.Parameters.Add("WTGSMTRS", OracleType.NVarChar).Value = dwData["WTGSMTRS"].ToString();
            or1.Parameters.Add("WTGREAPPI", OracleType.NVarChar).Value = dwData["WTGREAPPI"].ToString();
            or1.Parameters.Add("WTGRNAME", OracleType.NVarChar).Value = dwData["WTGRNAME"].ToString();
            or1.Parameters.Add("WTGCHORE", OracleType.NVarChar).Value = dwData["WTGCHORE"].ToString();
            or1.Parameters.Add("WTGRDENS", OracleType.NVarChar).Value = dwData["WTGRDENS"].ToString();
            or1.Parameters.Add("WTGRDENSTM", OracleType.NVarChar).Value = dwData["WTGRDENSTM"].ToString();
            or1.Parameters.Add("WTGRDENSTP", OracleType.NVarChar).Value = dwData["WTGRDENSTP"].ToString();
            or1.Parameters.Add("WTGKARTEN", OracleType.NVarChar).Value = dwData["WTGKARTEN"].ToString();
            or1.Parameters.Add("WTGPLATINEN", OracleType.NVarChar).Value = dwData["WTGPLATINEN"].ToString();
            or1.Parameters.Add("WTGNOPPEN", OracleType.NVarChar).Value = dwData["WTGNOPPEN"].ToString();
            or1.Parameters.Add("WTGANZRAPP", OracleType.NVarChar).Value = dwData["WTGANZRAPP"].ToString();
            or1.Parameters.Add("WTGRWRAPH", OracleType.NVarChar).Value = dwData["WTGRWRAPH"].ToString();
            or1.Parameters.Add("WTGRWRAPB", OracleType.NVarChar).Value = dwData["WTGRWRAPB"].ToString();
            or1.Parameters.Add("WTGRWRAPHFD", OracleType.NVarChar).Value = dwData["WTGRWRAPHFD"].ToString();
            or1.Parameters.Add("WTGRWRAPBFD", OracleType.NVarChar).Value = dwData["WTGRWRAPBFD"].ToString();
            or1.Parameters.Add("WTGPANELS", OracleType.NVarChar).Value = dwData["WTGPANELS"].ToString();
            or1.Parameters.Add("WTGSHEDS", OracleType.NVarChar).Value = dwData["WTGSHEDS"].ToString();
            or1.Parameters.Add("WTGNFLRH", OracleType.NVarChar).Value = dwData["WTGNFLRH"].ToString();
            or1.Parameters.Add("WTGNFLRA", OracleType.NVarChar).Value = dwData["WTGNFLRA"].ToString();
            or1.Parameters.Add("WTGNFTOLM", OracleType.NVarChar).Value = dwData["WTGNFTOLM"].ToString();
            or1.Parameters.Add("WTGNFTOLP", OracleType.NVarChar).Value = dwData["WTGNFTOLP"].ToString();
            or1.Parameters.Add("WTGMFLRH", OracleType.NVarChar).Value = dwData["WTGMFLRH"].ToString();
            or1.Parameters.Add("WTGMFLRA", OracleType.NVarChar).Value = dwData["WTGMFLRA"].ToString();
            or1.Parameters.Add("WTGMFTOLM", OracleType.NVarChar).Value = dwData["WTGMFTOLM"].ToString();
            or1.Parameters.Add("WTGMFTOLP", OracleType.NVarChar).Value = dwData["WTGMFTOLP"].ToString();
            or1.Parameters.Add("WTGHFLRH", OracleType.NVarChar).Value = dwData["WTGHFLRH"].ToString();
            or1.Parameters.Add("WTGHFLRA", OracleType.NVarChar).Value = dwData["WTGHFLRA"].ToString();
            or1.Parameters.Add("WTGHFTOLM", OracleType.NVarChar).Value = dwData["WTGHFTOLM"].ToString();
            or1.Parameters.Add("WTGHFTOLP", OracleType.NVarChar).Value = dwData["WTGHFTOLP"].ToString();
            or1.Parameters.Add("WTGFILLER", OracleType.NVarChar).Value = dwData["WTGFILLER"].ToString();
            Connect2Proxy(or1);
        }
    }
}
